# Maintainer: Tim Meusel <tim@bastelfreak.de>

pkgname=prometheus-bird-exporter
pkgver=1.4.1
pkgrel=1
pkgdesc='Exporter for bird metrics'
url='https://github.com/czerwonk/bird_exporter'
arch=('loong64' 'x86_64')
license=('Apache')

depends=('glibc')
makedepends=('go' 'git')
options=('!lto')

backup=('etc/conf.d/prometheus-bird-exporter')

source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/${pkgver}.tar.gz"
        prometheus-bird-exporter.conf
        prometheus-bird-exporter.service
        prometheus-bird-exporter.sysusers)

sha512sums=('54a59acb163962d9adefe96b8e64ee20871caaea2e5bfa755da473a5c1c58bd245c27fa13c4f039c6f0aa52eaba056c6705c493d5b614a6c7905241c58aec552'
            'b00b3db72e3389b7da3f68927951a87d76d937e81c6d35d0ccb7f091fb57bbe11feceb8626301b86f2e0c7be353282c3abfa4c5f2379c9e1e12a963074945411'
            'c3cba590d4a69372fbecda3e383f15c8492f8f2d8dc47f676513ffcabda4520f2b13a8dd368e2c271249d552a30ff79d28df6e173af729816751d9204feae211'
            '1a57390a23ce7021f2f40992f0a3c63c044e150621da8d34576eb81c0ecbe4411bb80a6e5e792a8aefffaf67d59b3df585304d2dc328046b9bc7fe033c82fe23')

build() {
  cd "bird_exporter-${pkgver}"

  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags ${LDFLAGS} \
      -X github.com/prometheus/common/version.Version=${pkgver} \
      -X github.com/prometheus/common/version.Revision=${pkgver} \
      -X github.com/prometheus/common/version.Branch=tarball \
      -X github.com/prometheus/common/version.BuildUser=someone@builder \
      -X github.com/prometheus/common/version.BuildDate=$(date -d=@"$SOURCE_DATE_EPOCH" +%Y%m%d-%H:%M:%S)" \
    .
}

check() {
  cd "bird_exporter-${pkgver}"

  #make collector/fixtures/sys/.unpacked
  #go test ./...
  go test ./... -v -covermode=count
  #./end-to-end-test.sh
}

package () {
  install -Dm644 prometheus-bird-exporter.conf "$pkgdir"/etc/conf.d/prometheus-bird-exporter
  install -Dm644 prometheus-bird-exporter.service "$pkgdir"/usr/lib/systemd/system/prometheus-bird-exporter.service
  install -Dm644 prometheus-bird-exporter.sysusers "$pkgdir"/usr/lib/sysusers.d/prometheus-bird-exporter.conf

  cd bird_exporter-$pkgver

  install -Dm755 bird_exporter "$pkgdir"/usr/bin/prometheus-bird-exporter

  install -Dm 644 README.md Dockerfile examples/kubernetes/daemonset.yaml -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
}
